<!DOCTYPE html>
<html>
    <head>
        <title>对象  </title>
		<meta charset="utf-8" />
    </head>
    <body>

    </body>
    <script>
        var dog = {
            dogName: "lily",
            weight: "20kg",
            color: "black",
            age:2,
            jump: function(){
                if(this.age >= 2){
                    console.log(this.dogName + "can jump");
                }
            }
        }
        /**
         * 定义一个对象cat
        */
        var cat = {
            catName:"lisa",
            pinzhong:"雪纳瑞",
            weight:"15kg",
            shout:function(){
                console.log(this.catName + "喵喵喵");
            }
        }
        var person = {
            personName: "zahngsan",
            age: 20,
            sayHello: function(){
                console.log("hello");

            }
        }
        //访问属性值
        //第一种写法，最常用写法，对象.属性名
        //对象.方法名
        console.log(person.sayHello());
        person.sayHello();

        //第二种写法，对象["属性名"]
        console.log(person["personName"]);
        person["sayHello"]();

        //区别  对象[变量]中括号中可以放变量
        var attr = "age";
        console.log(person[attr]);
         
        //访问对象不存在的属性，打印的是undefined
        console.log(person.hobby);
        
        person.hobby = ["swimming","football"];
        console.log(person);

        //添加一个weight
        person["weight"] = "45kg";
        
        //修改属性值
        person.age = 30;
        person["weight"] = 30;

        //删除属性值
        delete person.age;
        console.log(person.age);
    </script>
</html>